package com.newtouch.cq.base.starter.business.model.vo;

import com.newtouch.cq.base.starter.business.entity.SysMenu;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 路由树模型
 */
@Data
@Accessors(chain = true)
@JsonInclude(Include.NON_NULL)
@ApiModel("路由树模型")
public class RouteTreeModel implements Serializable, BaseParentAble<RouteTreeModel> {
	private static final long serialVersionUID = 6002921275643650309L;
	@ApiModelProperty("路由标识")
	protected Long id;
	@ApiModelProperty("父级路由标识")
	protected Long parentId;
	@ApiModelProperty("路由名称")
	protected String name;
	@ApiModelProperty("路由地址")
	protected String path;
	@ApiModelProperty("组件路径")
	protected String componentPath;
	@ApiModelProperty("子路由集合")
	protected List<RouteTreeModel> children;
	@ApiModelProperty("路由拓展信息")
	protected RouteMeta meta;
	
	public RouteTreeModel() {
		this.meta = new RouteMeta().setCache(true).setAuth(true).setTitle("index");
	}

	public RouteTreeModel(SysMenu menu) {
		super();
		this.id = menu.getId();
		this.parentId = menu.getParentId();
		this.name = menu.getMenuName();
		this.path = menu.getUrl();
		this.componentPath = menu.getComponent();
		this.meta = new RouteMeta().setCache(true).setAuth(true).setTitle(menu.getMenuName());
	}
	
	@Data
	@Accessors(chain = true)
	@ApiModel("路由拓展模型")
	public static class RouteMeta implements Serializable {
		private static final long serialVersionUID = 5829941979358557971L;
		@ApiModelProperty("拓展标题")
		protected String title;
		@ApiModelProperty("是否缓存")
		protected boolean cache = true;
		@ApiModelProperty("是否鉴权")
		protected boolean auth = true;
	}

	@Override
	public void addChildEle(RouteTreeModel child) {
		children.add(child);
	}

	@Override
	public void initialChildren() {
		children = new ArrayList<>();
	}
	
}

